package jjn.carl.array;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author Jiang Jining
 * @since 2023-06-29 22:39
 */
public class ToArrayDemo {
    public static void main(String[] args) {
        List<Integer> list = List.of(1, 2, 3, 4, 5);
        int[] converted = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            converted[i] = list.get(i);
        }
        System.out.println("Arrays.toString(array) = " + Arrays.toString(converted));
        
        List<int[]> list2 = new ArrayList<>();
        list2.add(new int[]{1, 2});
        list2.add(new int[]{3, 4});
        list2.add(new int[]{5, 6});
        int[][] arr = list2.toArray(new int[0][]);
        for (int[] part : arr) {
            System.out.println("Arrays.toString(part) = " + Arrays.toString(part));
        }
    }
}
